<?php
ob_start();
session_start();
date_default_timezone_set('Asia/Bangkok');
$id_member = $_SESSION["id_member"];
include("../connect.php");

$strSQL = "SELECT * FROM userlog WHERE id_member = '$id_member' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
$depart=$objResult["departid"];

$id_emp=$_GET['emp_id'];
//$strSQL1 = "SELECT * FROM employee INNER JOIN depart ON employee.de_id = depart.de_id LEFT JOIN comname ON employee.cn_id= comname.cn_id WHERE employee.emp_id = '$id_emp' ";
$strSQL1 = "SELECT * FROM employee INNER JOIN depart ON employee.de_id = depart.id INNER JOIN mail ON mail.emp_id = employee.emp_id WHERE employee.emp_id = '$id_emp' ";
$objQuery1 = mysql_query($strSQL1);
$objResult1 = mysql_fetch_array($objQuery1);
if($objResult1['mail_remark']==""){
		$objResult1['mail_remark'] = "-";
}

$strSQL3 = "SELECT * FROM comname WHERE emp_id = '$id_emp' ";
$objQuery3 = mysql_query($strSQL3);
$objResult3 = mysql_fetch_array($objQuery3);
$cn_number = $objResult3['cn_number'];
if($cn_number == null){
	$cn_number = "";
}else{
$strSQL2 = "SELECT * FROM product_detail where pd_id = $cn_number";
$objQuery2 = mysql_query($strSQL2);
$result2 = mysql_fetch_array($objQuery2);
mysql_query("set NAMES'TIS620'");
}
?>
<?
include "../connect.php";
$sql = "SELECT SUBSTRING(COLUMN_TYPE,3)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA='db_itmanager' 
    AND TABLE_NAME='permissionfile'
    AND COLUMN_NAME='per_permission' ";
$result = mysql_query($sql) or die( 'error getting enum field ' . mysql_error() );
$row = mysql_fetch_array($result);
$regex = "/'(.*?)'/";
preg_match_all( $regex , $row[0], $enum_array );
$enum_fields = $enum_array[0];
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Adinop Co., Ltd. was founded as an ingredients importer and local manufacturers’ distributor in 1986. We also function as an exporter of finished products</title>
      <link rel="stylesheet" href="../css/style.css"/>
	  <script language="javascript" src="../js/jquery/jquery-1.7.1.min"></script>
	  <script type="text/javascript" src="../fancybox/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
	  <script type="text/javascript" src="../fancybox/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
	  <link rel="stylesheet" type="text/css" href="../fancybox/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
 	  <link rel="stylesheet" href="../fancybox/style.css" />
	  <script type="text/javascript" src="autocomplete.js"></script>
	  <link rel="stylesheet" href="autocomplete.css"  type="text/css"/>
	  <link href="../css/button.css" rel="stylesheet" type="text/css" />
	  
	  <script type="text/javascript"> 
		$(function(){
			var objSet="#show_arti_topic";
			var objSetText="ค้นหา รหัส,ชื่อ";
			if($(objSet).val()==""){
					$(objSet).val(objSetText);
			}	
			$(objSet).focus(function(){
				if($(objSet).val()==objSetText){
						$(objSet).val("");
				}	
			}).blur(function(){
				if($(objSet).val()==""){
						$(objSet).val(objSetText);
				}	
			});
		});
	   </script>
	  <script type="text/javascript">

		$(document).ready(function() {
		
			$("#addpermission").fancybox({
				'width'				: '70%',
				'height'			: '75%',
				'autoScale'			: true,
				'scrolling'		    : 'auto',
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'none',
				'type'				: 'iframe',
				'overlayColor'		: '#000',
				'hideOnOverlayClick': false,
				onCleanup   : function() {
                return window.location.reload();
					 }
			});



		});
	</script>
<script language="javascript">
			function CheckValidate()
			{

			for(i=1;i<=document.frmMain.hdnMaxLine.value;i++){

			if(eval("document.frmMain.txtper_description_"+i+".value")==""){
				alert('กรุณากรอกPath Serverบรรทัดที่..  ' + i +' ครับ');
				eval("document.frmMain.txtper_description_"+i+".focus();")
				return false;
					}
			
			if(eval("document.frmMain.permission_"+i+".value")==""){
				alert('กรุณาเลือกPermissionบรรทัดที่..  ' + i +' ครับ');
				eval("document.frmMain.permission_"+i+".focus();")
				return false;
					}
				}

			}
			
			function CreateSelectOption(ele)
			{
				var objSelect = document.getElementById(ele);
			var Item = new Option("เลือก permission", ""); 
			objSelect.options[objSelect.length] = Item;
					var Item = new Option("r", "r"); 
			objSelect.options[objSelect.length] = Item;
					var Item = new Option("w", "w"); 
			objSelect.options[objSelect.length] = Item;
					var Item = new Option("m", "m"); 
			objSelect.options[objSelect.length] = Item;
/*
				var objSelect = document.getElementById(ele);
				var Item = new Option("เลือก permission", ""); 
				objSelect.options[objSelect.length] = Item;
				<?
				for($i=0;$i<3;$i++)
				{
				?>
				var Item = new Option("<?=$enum_fields[$i];?>", "<?=$enum_fields[$i];?>"); 
				objSelect.options[objSelect.length] = Item;
				<?
				}
				?>
*/
			}
/*
			function OpenPopup(intLine)
			{
				window.open('?Line='+intLine,'myPopup','width=420,height=600,toolbar=0, menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=900,top=50');
			}
*/
			function CreateNewRow()
			{
				var intLine = parseInt(document.frmMain.hdnMaxLine.value);
				intLine++;
					
				var theTable = document.getElementById("tbExp");
				var newRow = theTable.insertRow(theTable.rows.length)
				newRow.id = newRow.uniqueID

				var newCell
				
				//*** Column No ***//
				newCell = newRow.insertCell(0);
				newCell.id = newCell.uniqueID;
				newCell.setAttribute("className", "css-name");
				newCell.innerHTML = "<center>"+intLine+"</center>";

				//*** Column product_code ***//
				newCell = newRow.insertCell(1);
				newCell.id = newCell.uniqueID;
				newCell.setAttribute("className", "css-name");
				newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"70\" NAME=\"txtper_description_"+intLine+"\"  ID=\"product_code_"+intLine+"\" VALUE=\"\" </center>";

				//*** Column 4 ***//
				newCell = newRow.insertCell(2);
				newCell.id = newCell.uniqueID;
				newCell.setAttribute("className", "css-name");
				newCell.innerHTML = "<center><SELECT NAME=\"permission_"+intLine+"\" ID=\"permission_"+intLine+"\"></SELECT></center>";

				//*** Create Option ***//
				CreateSelectOption("permission_"+intLine)
			
				document.frmMain.hdnMaxLine.value = intLine;
			}
			
			function RemoveRow()
			{
				intLine = parseInt(document.frmMain.hdnMaxLine.value);
				if(parseInt(intLine) > 0)
				{
						theTable = document.getElementById("tbExp");				
						theTableBody = theTable.tBodies[0];
						theTableBody.deleteRow(intLine);
						intLine--;
						document.frmMain.hdnMaxLine.value = intLine;
				}	
			}	
		</script>

    </head>
    <body onload="CreateNewRow();"> 
        <body class="body">

            <table align="center" width="90%">
                <tr>
                    <td colspan="2" class="header" >
                      <img src="../images/logo.png"> ใบประวัติสิทธิ์การเข้าถึงข้อมูล 
                        <hr/>
                    </td>
                </tr >
              </table>

<form action="insert_permission.php" method="post" name="frmMain" id="frmMain" onsubmit="return CheckValidate();">
<fieldset>
<legend class="nameTitle">ข้อมูลส่วนตัว</legend>
<table width="100%" border="0" class="inputcontenttable">
  <tr>
    <th width="30%">
      <div align="right">Employee ID : </div></th>
    <th><div align="left">
      <input type="text" name="txtEmployee_id" id="txtEmployee_id" size="20" maxlength= "8" value="<?=$objResult1["emp_id"];?>" placeholder="รหัสเจ้าหน้าที่" onkeypress="KeyCodeInt()" readonly=""/>
	  <span id="mySpan"></span></div></th>

	  <th width="12%">
      <div align="right">Department : </div></th>
	   <td><input type="text" name="txtDepartment" id="txtDepartment" size="20" value="<?=$objResult1["departname"];?>" readonly=""/></td>
  </tr>

  <tr>
    <th width="25%">
      <div align="right">Computer ID : </div></th>
    <th><div align="left">
      <input type="text" name="txtCon_id" id="txtCon_id" size="20" value="<?=$result2['pd_name'];?>" readonly=""/>
	  <span id="mySpan1"></span></div></th>
    </div></th>

	<th width="12%">
	<? date_default_timezone_set('Asia/Bangkok'); ?>
      <div align="right">Start Date : </div></th>
	  <td><input type="text" name="txtStartdate" id="txtStartdate" size="20" value="<?=$objResult1["emp_startDate"];?>" readonly=""/></td>
  </tr>

  <tr>
    <th width="25%">
      <div align="right">Name (ENG) : </div></th>
    <th><div align="left">
      <input type="text" name="txtName_eng" id="txtName_eng" size="20" value="<?=$objResult1["emp_nameEng"];?>" readonly=""/>
    </div></th>

	<th width="12%">
      <div align="right">Username : </div></th>
	  <td><input type="text" name="txtUsername" id="txtUsername" size="20" value="<?=$objResult1["mail_username"];?>" readonly=""/></td>
  </tr>

  <tr>
    <th width="25%"> 
	<div align="right">Surname (ENG) : </div></th>
    <th width="236"><div align="left">
      <input type="text" name="txtSurname_eng" id="txtSurname_eng" size="20" value="<?=$objResult1["emp_surnameEng"];?>" readonly="" />
    </div></th>

	<th width="12%">
      <div align="right">Remark : </div></th>
	  <td><input type="text" name="txtRemark" id="txtRemark" value="<?=$objResult1["mail_remark"];?>" size="30" readonly=""/></td>
  </tr>
    </tr>
</table>
<br/>
 </fieldset>
 <br/>

						<div align ="center">
						 
								
								   <table width="800" border="0" id="tbExp" class="simply">
							  
									<tr>
										<th width="76" align="center"><b>ลำดับ</b></th>
										<th width="139" align="center"><b>รายละเอียดเซิฟเวอร์</b></th>
										<th width="139" align="center"><b>สิทธิ์การเข้าข้อมูล</b></th>
										
									</tr>
									</table>
								  
									<br />	
									<div style="width:800px" align="left">	
									<input type="hidden" name="hdnMaxLine" value="0">
									<input name="btnAdd" type="button" id="btnAdd" value="+" onClick="CreateNewRow();" class="button-link">
									<input name="btnDel" type="button" id="btnDel" value="-" onClick="RemoveRow();" class="button-link">
									<input type="submit" name="btnSubmit" value="ตกลง" class="button-link">
									</div>
								</form>
						</div>

                    </td>
                </tr> 

               
            </table>
        </body>
</html>